home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / mgraph / trans.h < prev    next >
Text File  |  1994-03-22  |  2KB  |  82 lines

  1. /* Copyright 1994 Ralph Gonzalez */
  2.  
  3. /*
  4. *    FILE:        trans.h
  5. *    AUTHOR:        R. Gonzalez
  6. *    CREATED:    March 15, 1994
  7. *
  8. *    Defines 3D transformation (using trans. matrix) for mgraph
  9. *    application, and other coordinate operations.
  10. */
  11.  
  12. # include    "boolean.h"
  13.  
  14. /******************************************************************
  15. *    2D coordinate
  16. ******************************************************************/
  17. typedef struct    Coord2
  18. {
  19.     double    x,
  20.             y;
  21. } Coord2;
  22.  
  23. /******************************************************************
  24. *    3D coordinate
  25. ******************************************************************/
  26. typedef struct    Coord3
  27. {
  28.     double    x,
  29.             y,
  30.             z;
  31. } Coord3;
  32.  
  33. /******************************************************************
  34. *   camera struct.  The camera's location is given in world
  35. *    coordinates.  If you were to translate the camera to the
  36. *    origin of the world coordinate system, then: YAW is the angle
  37. *    the camera is pointing as rotated about the world's vertical
  38. *    (y) axis (with respect to the direction of the world z axis);
  39. *    PITCH is the angle it is pointing with respect to the world
  40. *    horizontal (x-z) plane; ROLL is the angle the camera's "up"
  41. *    direction makes from the world's y axis, as measured about the
  42. *    axis in which the camera is pointing.  Note that yaw and roll
  43. *    are undefined when pitch is PI/2 or -PI/2; i.e., when the
  44. *    camera points straight up or down.
  45. ******************************************************************/
  46. typedef struct    Camera
  47. {
  48.     double    x,
  49.             y,
  50.             z,
  51.             yaw,
  52.             pitch,
  53.             roll;
  54. } Camera;
  55.  
  56. /******************************************************************
  57. *    functions
  58. ******************************************************************/
  59. /*    Coord3 functions:
  60. */
  61. void    set_coord(Coord3*,double,double,double);
  62. void    equate_coord(Coord3*,Coord3);
  63.  
  64. /*    Camera and projection functions:
  65. */
  66. void    set_camera(Camera*,double,double,double,double,double,double);
  67. void    set_world_to_camera(double[4][4],Camera);
  68. boolean    project(Coord2*,Coord3,double[4][4],double);
  69.  
  70. /*    transformation functions:
  71. */
  72. void    initialize_trans(double[4][4]);
  73. void    combine_trans(double[4][4],double[4][4]);
  74. void    equate_trans(double[4][4],double[4][4]);
  75. void    set_translation(double[4][4],double,double,double);
  76. void    set_scaling(double[4][4],double,double,double);
  77. void    set_rotation_x(double[4][4],double);
  78. void    set_rotation_y(double[4][4],double);
  79. void    set_rotation_z(double[4][4],double);
  80. void    apply_trans(Coord3*,double[4][4]);
  81.  
  82.